<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script>
    // 13.求一组数中的最大值和最小值，以及所在位置的下标
    // 先随机一组数
    var arr = [];
    for(var i = 0; i < 10; i++){
      var num = Math.round(Math.random()*100);
      arr.push(num);
    }

    //求最大值和下标值
    function maxNum(arr){
      var maxNum = arr[0];
      var maxIndex = 0;
      for(var i = 0; i < arr.length; i++) {
        if (arr[i] > maxNum) {
          maxNum = arr[i];
          maxIndex = i;
        }
      }
      return '最大值是' + maxNum + '所在的下标为' + maxIndex;
    }

    //求最小值和小标
    function minNum(arr){
      var minNum = arr[0];
      var minIndex = 0;
      for(var i = 0; i < arr.length; i++) {
        if ( arr[i] < minNum) {
          minNum = arr[i];
          minIndex = i;
        }
      }
      return '最小值是' + minNum + '所在的下标为' + minIndex;
    }
    console.log(maxNum(arr));
    console.log(minNum(arr));
  </script>
</head>
<body>
  
</body>
</html>